/* LogTable.m - The log date table.
 *
 * Copyright (C) 2008 Yuuichi Teranishi
 *
 * This file is derived from Stumbler, a program developed by iphone-wireless
 * project.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * published by the Free Software Foundation.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; If not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
#include <unistd.h>

#import <GraphicsServices/GraphicsServices.h>
#import "LogTable.h"

@implementation LogTable
- (int)swipe:(int)type withEvent:(struct __GSEvent *)event;
{
  CGPoint point = GSEventGetLocationInWindow(event);

  if (point.x < 100 || point.x > 200) {
    point.y -= 40;
    CGPoint offset = _startOffset; 
    NSLog(@"LogTable.swipe: %d %f, %f", type, point.x, point.y);
    
    point.x += offset.x;
    point.y += offset.y;
    int row = [ self rowAtPoint:point ];
    
    [ [ self visibleCellForRow:row column:0] 
      _showDeleteOrInsertion:YES 
      withDisclosure:NO
      animated:YES 
      isDelete:YES 
      andRemoveConfirmation:YES
      ];
    return [ super swipe:type withEvent:event ];
  }
}

@end

@implementation LogCell

- (void)removeControlWillHideRemoveConfirmation:(id)fp8
{
  [ self _showDeleteOrInsertion:NO
	 withDisclosure:NO
	 animated:YES
	 isDelete:YES
	 andRemoveConfirmation:YES
    ];
}

- (void)_willBeDeleted
{
  NSLog(@"Delete %@",
	[ _dates objectAtIndex: [ _table _rowForTableCell: self ]]);
  [ _logdb deleteDate:
	     [ _dates objectAtIndex: [ _table _rowForTableCell: self ]] ];
  [ _dates removeObjectAtIndex: [ _table _rowForTableCell: self ] ];
}

- (void)setTable:(LogTable *)table {
  _table = table;
}

- (void)setDates:(NSMutableArray *)dates {
  _dates = dates;
}

- (void)setLogDB:(LogDB *)logdb {
  _logdb = logdb;
}

@end

